package com.fengwk.user.controller;

import java.util.Collection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fengwk.support.util.ResultUtils;
import com.fengwk.user.service.ValidationService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(tags = "校验")
@RestController
@RequestMapping("/api/validation")
public class ValidationController {

	@Autowired
	private HttpServletRequest request;
	@Autowired
	private HttpServletResponse response;
	
	@Autowired
	private ValidationService validationService;

	@ApiOperation(
			value = "角色列表校验", 
			response = boolean.class)
	@PostMapping("/validationRoles")
	public void validationRoles(
			@ApiParam(value = "用户id", required = true) @RequestParam(value = "userId", required = false) Long userId, 
			@ApiParam(value = "角色列表", required = true) @RequestParam(value = "roles", required = false) Collection<String> roles) {
		ResultUtils.returnJsonResult(request, response, validationService.validationRoles(userId, roles));
	}

	@ApiOperation(
			value = "权限列表校验", 
			response = boolean.class)
	@PostMapping("/validationPermissions")
	public void validationPermissions(
			@ApiParam(value = "用户id", required = true) @RequestParam(value = "userId", required = false) Long userId, 
			@ApiParam(value = "权限列表", required = true) @RequestParam(value = "permissions", required = false) Collection<String> permissions) {
		ResultUtils.returnJsonResult(request, response, validationService.validationPermissions(userId, permissions));
	}
	
}
